//package com.hypo.controller;
//
//import com.hypo.pojo.Result;
//import jakarta.servlet.http.Cookie;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import jakarta.servlet.http.HttpSession;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//@RestController
//public class SessionController {
//    /**
//     * session存储在浏览器服务端
//     */
//
//    @GetMapping("/s1")
//    public Result session1(HttpSession session) {
//        int i = session.hashCode();
//        System.out.println("session.hashCode() " + i);
//        session.setAttribute("loginUser", "milan");
//        return Result.success();
//    }
//
//    @GetMapping("/s2")
//    public Result session2(HttpServletRequest request) {
//        HttpSession session = request.getSession();
//        int i = session.hashCode();
//        System.out.println("session.hashCode() " + i);
//        Object loginUser = session.getAttribute("loginUser");
//        return Result.success(loginUser);
//    }
//
//    /**
//     * cookie浏览器存储在客户端
//     */
//    @GetMapping("/c1")
//    public Result cookie1(HttpServletResponse response) {
//        response.addCookie(new Cookie("login_userName", "jack"));
//        return Result.success();
//    }
//
//    @GetMapping("/c2")
//    public Result cookie2(HttpServletRequest request) {
//        Cookie[] cookies = request.getCookies();
//        for (Cookie cookie : cookies) {
//            if (cookie.getName().equals("login_userName")) {
//                System.out.println("login_userName" + cookie.getValue());
//            }
//        }
//        return Result.success();
//    }
//}
